<?php
namespace Hilaoyu\ComputeCloudClient;


use Hilaoyu\Utils\UtilArr;

class AssetModels
{
    /**
     * @var array<AssetModel>  
     */
    protected $models = [];

    public function __construct(array $models=[]){
        $this->setModels($models);
    }

    public function setModels(array $models=[]){
        $this->models = $models;
    }

    public function isEmpty(){
        return empty($this->models);
    }
    public function isNotEmpty(){
        return !$this->isEmpty();
    }

    public function push(AssetModel $model){
        $this->models[] = $model;
        return $this;
    }

    public function unshfit(AssetModel $model){
        array_unshift($this->models,$model);
    }

    public function toArray(){
        return $this->models;
    }


    public function filter($callback){
        $arr = array_filter($this->models, $callback, ARRAY_FILTER_USE_BOTH);
        return new static($arr);
    }

    public function first($callback):?AssetModel {
        return UtilArr::first($this->models,$callback);
    }

    public function count(){
        return count($this->models);
    }
}
